package com.example.wananrdroid.fragment.zhufragment;


import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.example.wananrdroid.Main2Activity;
import com.example.wananrdroid.R;
import com.example.wananrdroid.adapter.WenAdapter;
import com.example.wananrdroid.base.BaseFragment;
import com.example.wananrdroid.bean.WenBean;
import com.example.wananrdroid.presenter.WenPresenter;
import com.example.wananrdroid.view.WenView;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * A simple {@link Fragment} subclass.
 */
public class WenFragment extends BaseFragment<WenPresenter> implements WenView {
    @BindView(R.id.wen_re)
    RecyclerView mwen_re;
    @BindView(R.id.wen_toolbar)
    Toolbar mwen_toolbar;
    private ArrayList<WenBean.DataBean.DatasBean> datasBeans;
    private WenAdapter wenAdapter;

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        mwen_toolbar.setTitle("");
        mwen_re.setLayoutManager(new LinearLayoutManager(getContext()));
        mwen_re.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayout.VERTICAL));
        datasBeans = new ArrayList<>();
        wenAdapter = new WenAdapter(getContext(), datasBeans);
        mwen_re.setAdapter(wenAdapter);
        wenAdapter.setOnContextClickListener(new WenAdapter.OnContextClickListener() {
            @Override
            public void oncontextclicklistener(View v, int position) {
                Intent intent = new Intent(getContext(), Main2Activity.class);
                String link = datasBeans.get(position).getLink();
                intent.putExtra("url",link);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void initPresenter() {
        mPresenter=new WenPresenter();
        mPresenter.getwendata();
    }
    @Override
    protected int getLayout() {
        return R.layout.fragment_wen;
    }

    @Override
    public void onSuccess(WenBean wendata) {
        datasBeans.addAll(wendata.getData().getDatas());
        wenAdapter.notifyDataSetChanged();
    }

    @Override
    public void onFali(String error) {
    }

    @Override
    public void showToast(String str) {

    }
}
